package com.yitiao.data_algorithms.structure.queue;

import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBlockingQueueSource {
    public static void main(String[] args) {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        queue.add(1);
        queue.add(2);
        queue.add(3);
//        System.out.println(queue.peek());
//        System.out.println(queue.poll());
        /**
         * #dequeue()  // help GC,同时遍历时保证多线程下的数据一致性
         * private E dequeue() {
         *         Node<E> h = head;
         *         Node<E> first = h.next;
         *         h.next = h; // help GC
         *         head = first;
         *         E x = first.item;
         *         first.item = null;
         *         return x;
         *     }
         */
        System.out.println(queue.remove());
        System.out.println(queue);
    }
}
